//
//  FourViewController.swift
//  swiftTS
//
//  Created by 航电 on 2020/3/4.
//  Copyright © 2020 航电. All rights reserved.
//

import UIKit

class FourViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        self.title = "表联动";
        // Do any additional setup after loading the view.
        self.onCreateUIForNavigation();
        self.onCreateUIForView();
    }
    

   //TODO:创建UI
    func onCreateUIForNavigation() {
        let backItem = UIBarButtonItem(title: "返回", style: .plain, target: self, action: #selector(backAction));
        self.navigationItem.leftBarButtonItem = backItem;
        
        self.navigationController?.navigationBar.barTintColor = .lightGray;
        
        //设备背景图片barTintColor就无效
//        self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default);
    }
    
    func onCreateUIForView() {
        self.view.backgroundColor = .white;
        
        let titleArr = ["tableView和tableView联动","tableView和collectionView联动"];
        var itemTop = 88;
        for index in 0 ... titleArr.count-1 {
            let title = titleArr[index];
            itemTop = itemTop + index * 80 + 30;
            
            let bt = UIButton(type: .custom);
            bt.frame = CGRect(x: 60, y: itemTop, width: Int(screenMainSize.width-CGFloat(60*2)), height: 50);
            bt.setTitle(title, for: .normal);
            bt.setTitleColor(UIColor.green.withAlphaComponent(0.75), for: .normal);
            bt.tag = 500 + index;
            bt.layer.cornerRadius = 5;
            bt.layer.masksToBounds = true;
            bt.layer.borderWidth = 1;
            bt.layer.borderColor = UIColor.lightGray.cgColor;
            bt.addTarget(self, action: #selector(onClickBtForView(bt:)), for: .touchUpInside);
            self.view.addSubview(bt);
        }
    }

    //TODO:Actions
    //TODO:Private Actions
    @objc func backAction() {
        self.navigationController?.dismiss(animated: true, completion: nil);
    }
    
    //TODO:Public Actions
    @objc func onClickBtForView(bt:UIButton) {
        switch bt.tag-500 {
        case 0:
            let vc = FourTTViewController();
            self.navigationController?.pushViewController(vc, animated: true);
        case 1:
            let vc = FourTCViewController();
            self.navigationController?.pushViewController(vc, animated: true);
        default:
            ""
        }
    }
}
